home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / lib / tags.uem < prev    next >
Text File  |  1995-07-21  |  4KB  |  143 lines

  1. ;  @(#)    TAGS - microEmacs v3.9i+ macro file to emulate vi tags cmd
  2. ;
  3. ;    Uses tags file from either "ctags" or "ctags -x  ... > tags"
  4. ;        MJH Oct 1989  v1.0
  5. ;    Bound to C-X T.....
  6. ; CTAGS fmt 
  7. ;   tag file vi-search-cmd
  8. ; CTAGS -x fmt
  9. ;   tag lnno file search-string
  10. ;
  11. ; uses !return rightout xtnsion so can treat uargs value as flag 
  12. ;   ( since counted iterations of this macro isn't sensible )
  13. ;
  14. ; Variables :
  15. ;     %tag     - tag string
  16. ;    %line    - line containg tag in tags file
  17. ;    %i    - start pos of field in line
  18. ;     %len    - len of field in line
  19. ;       %lnno   - lineno from tags file 
  20. ;     %filename - filename field from tags line
  21. ;    %pattern -  pattern field from tags line
  22.  
  23. set $discmd FALSE
  24. 25 store-macro
  25.  
  26.     ; Default uargs val - look  under cursor
  27.     !if &equal $uarg 1
  28.     !if &or &equal $curchar 20 &equal $curchar 9
  29.         next-word
  30.     !else
  31.         !while &equal 0 &sindex " (},*!~t~n=" $char
  32.         backward-character
  33.         !endwhile
  34.         forward-character
  35.             ; previous-word
  36.     !endif
  37.     set %tag &chr $curchar
  38.     forward-character
  39.     !while &equal 0 &sindex " (},~t~n" $char
  40.         set %tag &cat %tag $char
  41.         forward-character
  42.     !endwhile
  43.     !else               ; prompt for tagname 
  44.         set %tag @"Enter tag:"
  45.         !if &sequal %tag ""
  46.             write-message "%%No tag - aborted"
  47.             !return rightout
  48.         !endif
  49.     !endif
  50.  
  51.     set %tag &cat "^" %tag
  52.  
  53. ;    write-message &cat &cat "tag ["  %tag "]"
  54. ;    set %wait >k
  55.  
  56.     set-nmark "t" 
  57.     !force find-file "tags"     ; load tags file
  58.     !if &seq $status FALSE
  59.     write-message "%%Cannot load tags file"
  60.     !return rightout
  61.     !endif
  62.     add-mode "magic"            ; now search it
  63.     beginning-of-file
  64.     !force search-forward %tag
  65.     !if &seq $status FALSE
  66.     write-message &cat "%% cannot find tag" %tag
  67.     !return rightout
  68.     !endif
  69.         
  70.     set %line $line
  71.     
  72.     ; break sections for tag, linenumber and pattern from tags file
  73.     next-word
  74.     set %lnno 0
  75.     !if ¬ &equal 0 &sindex "0123456789" $char       ; ctags -x file
  76.     set %i &add $curcol 1
  77.         !while &equal 0 &sindex " ~t" $char        ; space and tab 
  78.         forward-character
  79.         !endwhile
  80.     set %len &add &sub $curcol %i 1
  81.     set %lnno &mid %line %i %len
  82. ;write-message &cat &cat "DBG: lnno ["  %lnno "]"
  83. ;set %wait >k
  84.     next-word
  85.         set %i &add $curofs 1                               ; filename 
  86.     !else
  87.         set %i &add $curofs 1                               ; filename 
  88.     !endif
  89.  
  90.     !while &equal 0 &sindex " ~t" $char         ; not space/tab 
  91.     forward-character
  92.     !endwhile
  93. ;   set %len &add &sub $curcol %i 1
  94.     set %len &add &sub $curofs %i 1
  95.     set %filename &mid %line %i %len
  96. ;write-message &cat &cat "DBG: file ["  %filename "]"
  97. ;set %wait >k
  98.     
  99.     next-word               ; search string
  100. ;   set %i &add $curcol 1
  101.     set %i &add $curofs 1
  102.     set %pattern &right %line %i
  103.     set %i &len %pattern
  104.     !if ¬ &equal 0 &sindex  "/?" &right %pattern %i   ; std tags file ??
  105.     set %i &sub %i 1
  106.     set %pattern &left %pattern %i
  107.     !endif
  108. ;write-message &cat &cat "DBG: pattern ["  %pattern "]"
  109. ;set %wait >k
  110.     !if &greater &len %pattern 30
  111.         set %pattern &left %pattern 30
  112.     !endif
  113.  
  114. ;++once have or as loading pattern need to quote any regexp metachars    
  115.  
  116.     ; Now load file and search through it
  117.     !force find-file  %filename
  118.     !if &seq $status FALSE
  119.     write-message &cat "%% Cannot find file " %filename
  120.     !return rightout
  121.     !endif
  122.     
  123.     beginning-of-file
  124.     !if &greater %lnno 0
  125.     goto-line &sub %lnno 20
  126.     !else
  127.         add-mode "magic"
  128.     !endif
  129.     
  130.     !force search-forward %pattern
  131.     !if &seq $status FALSE
  132.     write-message &cat "%%Cannot find pattern in file"
  133.         !return rightout
  134.     !endif
  135.     beginning-of-line
  136.     write-message "Tag Successful"
  137.     set-nmark "T" 
  138.     !return rightout
  139. !endm
  140. set $discmd TRUE
  141. bind-to-key execute-macro-25 ^XT
  142.  
  143.